package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;
import com.qiantu.phone.app.AppApplication;
import com.qiantu.phone.bean.AddDeviceMethodBean;
import com.qiantu.phone.ui.activity.AddDevice1Activity;

/**
 *    author : Android 轮子哥
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/09/22
 *    desc   : 状态数据列表
 */
public final class AddDeviceMethodAdapter extends AppAdapter<AddDeviceMethodBean> {

    public AddDeviceMethodAdapter(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final ImageView iconMethod;
        private final TextView tvMethodName;

        private ViewHolder() {
            super(R.layout.item_add_method);
            iconMethod = findViewById(R.id.icon_method);
            tvMethodName = findViewById(R.id.tv_method_name);
        }

        @Override
        public void onBindView(int position) {
            AddDeviceMethodBean item = getItem(position);
            switch (item.getProductLinkType()){
                case AddDevice1Activity.TYPE_WIRED_ADD:
                    iconMethod.setImageDrawable(AppApplication.getInstance().getThemeDrawable(R.attr.icon_add_device_serialnumber));
                    tvMethodName.setText(R.string.serial_number_add);
                    break;
                case AddDevice1Activity.TYPE_WIFI_ADD:
                    iconMethod.setImageDrawable(AppApplication.getInstance().getThemeDrawable(R.attr.icon_add_device_wifi));
                    tvMethodName.setText(R.string.wifi_add);
                    break;
            }
        }
    }

    @Override
    public long getItemId(int position) {
        return getData().get(position).hashCode();
    }
}